$(function () {
    // 获取收藏信息
    // var loading = weui.loading('loading', {
    //     className: 'custom-classname'
    // });

//插入定位box
    var templ = '<span class="box location-box"></span>'
    $(templ).appendTo($("#flow-list"));
    //上滑事件触发瀑布流
    $("html, body").scrollTop(1);
    var index = 1;
    var pageNum = 10;
    $("#flow-list").waterfall({
        itemClass: ".box",
        minColCount: 2,
        spacingHeight: 10,
        isFadeIn: true,
        resizeable: true,
        ajaxCallback: function (success, end) {

            findAllGoodsItem(pageNum, index)
            console.log("调用了一次")
            console.log(index)
            console.log(pageNum)
            success();
            index++;
            end();
            $(".location-box").remove();
        }
    });


    function findAllGoodsItem(pageSize, page) {
        var result = Model.goods.collectionGoods({
            pageSize: pageSize,
            page: page
        });
        if (result.goods.length == 0) {
            $('#flow-list').append('<p style="position: absolute;z-index: 9999; bottom: 4.5rem;left: 43%;color: #666666;">没有更多数据了</p>');
        }
        for (var i = 0; i < result.data.length; i++) {
            var item = '<div class="box"<a  href="goods_detail.html?id=' + result.goods[i].id + '"><img src="' + ((result.goods[i].goodsImg.length > 0) ? result.goods[i].goodsImg[0].image : '') + '" /><p class="flow-list-name">' + result.goods[i].content + '</p>' +
                '<p class="flow-list-price">￥ ' + result.goods[i].price + '</p>' +
                '</a>' +
                '<a class="weui-btn delete-collect" data-id="' + result.goods[i].id + '">删除收藏</a></div>'
            $('#flow-list').append(item);
        }

    }
})

// 删除收藏按钮
$(document).on('click', '.delete-collect', function () {
    var id = $(this).attr('data-id');
    var result = Model.goods.deleteCollection({
        id: id
    });
    if (result.code == 1) {
        weui.toast('删除收藏成功', {
            duration: 1500,
            className: 'custom-classname',
            callback: function () {
                location.reload();
            }
        });
    }
});